package com.sky.web.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sky.domain.Book;
import com.sky.service.BookService;

public class QueryBookByIdServlet extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取请求参数
		String id = request.getParameter("id");
		//2.处理业务逻辑
		//根据指定的id查询这本书
		BookService bookService =new BookService();
		Book book;
		try {
			book = bookService.queryBookById(id);
			//3.分发转向
			//如果查询成功，直接把书的信息传递到edit.jsp回显数据
			request.setAttribute("book", book);
			request.getRequestDispatcher("product/edit.jsp").forward(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}


}
